// 入口文件
// 构造函数
const path = require("path")
const Koa = require("koa2")
const koaBody = require("koa-body")
const static = require("koa-static")
const koaJwt = require("koa-jwt")
// const cors = require("cors")

const router = require("./routers/router")
const app = new Koa()
// app.use(cors())
// app.use(bodyParser())
const SECRET = require("./SECRET") // 密钥
// secret 加密字符串

app.use(koaJwt({ secret: SECRET }).unless({ path: [/^\/login/] }));
app.use(static(path.join(__dirname,"./uploadfiles")))
app.use(koaBody({
    multipart:true,
    formidable:{
        uploadDir:path.join(__dirname,"./uploadfiles"),
        keepExtensions:true
    }
}));
const port = 5000

app.use(router)
app.listen(port,() => {
    console.log("Server is running")
})
// eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InhpYW9xaWFuZyIsImlhdCI6MTY1NzcwODUyOCwiZXhwIjoxNjYwMzAwNTI4fQ.t3j8JDo9XaDofjpaY20dxRkRtA-aL67ShPL4xgswdKc
// eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InhpYW9xaWFuZyIsImlhdCI6MTY1NzcwOTE1MSwiZXhwIjoxNjYwMzAxMTUxfQ.wiFau8K2iQjrEl8adboFFlkHcEEnVATnWgnWgBXBZCk